/**
 * 
 */
package fr.upvm.lem3.vm3d.ui.swing.dataload;

import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.util.Vector;

import javax.swing.AbstractButton;
import javax.swing.AbstractListModel;
import javax.swing.DefaultListModel;
import javax.swing.JList;
import javax.swing.ListModel;
import javax.swing.TransferHandler;
import javax.swing.event.ListDataListener;

/**
 *******************************************************************
 *MyListModel.java
 *18.02.2012
 *@author Guy Nougouapi
 * @param <E>
 *******************************************************************
 *
 *******************************************************************
 */
public class MyListModel<String> extends DefaultListModel<String> {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	public MyListModel(){
		super();
	}
	public MyListModel( Vector<String> listData){
		super();
		addElements(listData);
	}
	/**
	 * add the element from the given vector into the listModel
	 * @param vec
	 */
	public void addElements( Vector<String> vec){
		for(String el: vec){
			super.addElement(el);
		}
	}
	
	/**
	 * @param e: Element to Add
	 */
	public void addElement( String e){
		super.addElement(e);
	}
	
	public void add(int index, String line){
		super.add(index, line);
	}
	
	/**
	 * Add all the element of the vector vec into at the end of this listModel
	 */
	public void addAll( Vector<String> vec){
		for(String str: vec){
			super.addElement(str);
		}
	}
	
	/**
	 * Get all the element inside the specified range
	 */
	public Vector<String> getElements(int[] indices){
		Vector<String> elts = new Vector<String>();
		for(int i=0; i<indices.length; i++){
			elts.add(super.elementAt(indices[i]));
		}
		return elts;
	}
	/**
	 * register the listener to hear change occurred on this Model {@link ListModel}
	 * @param listener
	 */
	public void addaddListDataListener(ListDataListener listener){
		super.addListDataListener(listener);
	}  
  /**
   * remove the element inside the given range
   */
  public void removeRange(int fromIndex, int toIndex){
	  super.removeRange(fromIndex, toIndex);
  }
  
  /**
   * Delete the component at the specified index
   */
  public void removeElementAt(  int index){
	  super.removeElementAt(index);
  }
  
  @Override
  public String set(int index, String element) {
	  return super.set(index, element);
	  }
  
  /**
   * remove all element from this list and set the size to zero
   */
  public void clear(){
	  super.clear();
  }
  
  /**
   * get the all the data of this listModel
   */
  public Vector<String> getData(){
	  
	  int modelSize = super.getSize();
	  Vector<String> vec = new Vector<String>();
	  
	  for(int i = 0; i<modelSize; i++ ){
		  vec.add(super.get(i));
	  }
	  return vec;
  }
}

